 
 $(document).ready(function(){
// var dt = localStorage.getItem("calculation_method");
// var dt2 = localStorage.getItem("price");
// var dt3 = localStorage.getItem("year");
// var dt4 = localStorage.getItem("lending_rate");
// console.log(dt);
// console.log(dt2);
// console.log(dt3);
// console.log(dt4);
//localStorage.clear();
//等额本息
//每月月供额=〔贷款本金×月利率×(1＋月利率)＾还款月数〕÷〔(1＋月利率)＾还款月数-1〕
//
//每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1
//
//〕
//每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
//
//总利息=还款月数×每月月供额-贷款本金

//等额本金还款法:
//每月月供额=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率
//每月应还本金=贷款本金÷还款月数
//每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率
//每月月供递减额=每月应还本金×月利率=贷款本金÷还款月数×月利率
//总利息=〔(总贷款额÷还款月数+总贷款额×月利率)+总贷款额÷还款月数×(1+月利率)〕÷2×还款月数-总贷款额
	
	var mortgage_Calculator = localStorage.getItem("mortgage_Calculator");
	
	if(mortgage_Calculator==1 || mortgage_Calculator==2){
			var price = localStorage.getItem("price");
			var proportion = localStorage.getItem("proportion");
			var pric2 = localStorage.getItem("pric2")*10000;
			var year2 = localStorage.getItem("year2");
			var lending_rate = localStorage.getItem("lending_rate");
			
			
			var for_the_month =(pric2*lending_rate/12*Math.pow((1+lending_rate/12),year2*12)) / (Math.pow((1+lending_rate/12),year2*12)-1); //月供
			var for_the_month_bx = Number(for_the_month);
			var interest = year2*12*for_the_month_bx - pric2;
			var interest_bx = Number(parseFloat(interest).toFixed(2));
			var amount_money = Number(parseFloat(for_the_month_bx * year2 * 12-0).toFixed(2));
			
			$('#total_loan label').html(pric2/10000);
			$('#loan_period label').html(year2*12);
			$('#average_monthly label').html(for_the_month_bx.toFixed(2));
			$('#interest label').html(interest_bx);
			$('#amount_money label').html(amount_money);
			
			$('#total_loan2 label').html(pric2/10000);
			
			var interest2 = ((pric2/(year2*12)+pric2*lending_rate/12)+pric2/(year2*12)*(1+lending_rate/12))/2*year2*12-pric2;
			var interest2_bj = Number(parseFloat(interest2).toFixed(2));
			$('#interest2 label').html(interest2_bj);
			
			var amount_money2 = Number((pric2*1 + interest2_bj*1).toFixed(2));
			
			$('#amount_money2 label').html(amount_money2);
			$('#loan_period2 label').html(year2*12);
			
			var tirst_month_also = (pric2/(year2*12))+(pric2*(lending_rate/12));
			var tirst_month_also_bj =  Number(parseFloat(tirst_month_also).toFixed(2));
			
			$('#tirst_month_also label').html(tirst_month_also_bj);
			
			var monthly_principal = pric2 / (year2*12)
			
			
//			for(var i=1; i<=year2*12; i++){
//				
//				var month = (pric2/(year2*12))+((pric2-monthly_principal*i)*(lending_rate/12))
//				
//				console.log(month);
//			}
			$('.loan_details_next').click(function(){
		
					window.location.replace("../repayment_details/还款明细.html");
					
		 			localStorage.setItem("monthly_principal", monthly_principal);   //每月应还本金
		 			localStorage.setItem("year2", year2);  //期限
		 			localStorage.setItem("pric2", pric2);  //贷款总额
		 			localStorage.setItem("lending_rate", lending_rate);  //年利率
		 			localStorage.setItem("mortgage_Calculator", 1);  
		
				});
				
			var myChart_one = echarts.init(document.getElementById('echart_box_one'));
			var option_one = {
			    toolbox: {
			        show : false,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'center',
			                        max: 1548
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : false,
			    series : [
			        {
			      
			            type:'pie',
			            radius : ['30%','50%' ],
			              center : ['50%', '65%'],
			            itemStyle : {
			                normal : {
			                    label : {
			                        show : true,
			       
			                        formatter:"{b}\n{c}",
			                        textStyle:{
			                        	fontSize:12
			                        }
			                    },
			                    labelLine : {
			                        show : true,
			                        length:20,
			                    }
			                },
			                emphasis : {
			                    label : {
			                        show : true,
			                        position : 'center',
			                        textStyle : {
			                            fontSize : '12',
			                            fontWeight : 'bold'
			                        }
			                    }
			                }
			            },
			            data:[
			                {value:pric2, name:'贷款总额'},
			                {value:interest_bx, name:'支付利息'}
			            ]
			        }
			    ]
		};
      // 为echarts对象加载数据 
        myChart_one.setOption(option_one);              
		
			var myChart_two = echarts.init(document.getElementById('echart_box_two'));
			var option_two = {
			    toolbox: {
			        show : false,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'center',
			                        max: 1548
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : false,
			    series : [
			        {
			        	
			            type:'pie',
			             radius : ['30%','50%' ],
			              center : ['50%', '65%'],
			            itemStyle : {
			                normal : {
			                    label : {
			                        show : true,
			                        formatter:"{b}\n{c}",
			                        textStyle:{
			                        	fontSize:12
			                        }
			                    },
			                    labelLine : {
			                        show : true,
			                        length:20,
			                    }
			                },
			                emphasis : {
			                    label : {
			                        show : true,
			                        position : 'center',
			                        textStyle : {
			                            fontSize : '14',
			                            fontWeight : 'bold'
			                        }
			                    }
			                }
			            },
			            data:[
			                {value:pric2, name:'贷款总额'},
			                {value:interest2_bj, name:'支付利息'}
			            ]
			        }
			    ]
		};
      // 为echarts对象加载数据 
        myChart_two.setOption(option_two);              
		
}
	else if(mortgage_Calculator==3){
			var price = localStorage.getItem("price");
			var proportion = localStorage.getItem("proportion");
			var pric2 = localStorage.getItem("pric2")*10000;
			var year2 = localStorage.getItem("year2");
			var price_hpf = localStorage.getItem("price_hpf")*10000;
			var lending_rate_hpf = localStorage.getItem("lending_rate_hpf");
			var price_commercial = localStorage.getItem("price_commercial")*10000;
			var lending_rate_commercial = localStorage.getItem("lending_rate_commercial");
			
			
			
			//等额本息
			var for_the_month =(price_hpf*lending_rate_hpf/12*Math.pow((1+lending_rate_hpf/12),year2*12)) / (Math.pow((1+lending_rate_hpf/12),year2*12)-1)+(price_commercial*lending_rate_commercial/12*Math.pow((1+lending_rate_commercial/12),year2*12)) / (Math.pow((1+lending_rate_commercial/12),year2*12)-1); //月供
			var for_the_month_bx = parseFloat(for_the_month);//月供保留两位小数
			var interest = year2*12*for_the_month_bx - pric2;//支付利息
			var interest_bx = parseFloat(interest).toFixed(2);//支付利息保留两位小数
			var amount_money =  (for_the_month_bx * year2 * 12).toFixed(2);//还款总额
			
			$('#total_loan label').html(pric2/10000);//贷款总额
			$('#loan_period label').html(year2*12);//贷款期限
			$('#average_monthly label').html(for_the_month_bx.toFixed(2));//月均还款
			$('#interest label').html(interest_bx);//支付利息
			$('#amount_money label').html(amount_money);//还款总额
			//等额本金	
			$('#total_loan2 label').html(pric2/10000);
			
			var interest2 =(((price_hpf/(year2*12)+price_hpf*lending_rate_hpf/12)+price_hpf/(year2*12)*(1+lending_rate_hpf/12))/2*year2*12-price_hpf)+(((price_commercial/(year2*12)+price_commercial*lending_rate_commercial/12)+price_commercial/(year2*12)*(1+lending_rate_commercial/12))/2*year2*12-price_commercial);
			var interest2_bj = parseFloat(interest2).toFixed(2);
			$('#interest2 label').html(interest2_bj);
			
			var amount_money2 = (pric2*1 + interest2_bj*1).toFixed(2);
			$('#amount_money2 label').html(amount_money2);
			$('#loan_period2 label').html(year2*12);
			
			var tirst_month_also = (price_hpf/(year2*12))+(price_hpf*(lending_rate_hpf/12))+(price_commercial/(year2*12))+(price_commercial*(lending_rate_commercial/12));
			var tirst_month_also_bj =  parseFloat(tirst_month_also).toFixed(2);
			
			$('#tirst_month_also label').html(tirst_month_also_bj);//首月还款
			
			var monthly_principal_hpf = price_hpf / (year2*12)//月均还款本金-公积金
			var monthly_principal_commercial = price_commercial / (year2*12)//月均还款本金-商业贷
			
			$('.loan_details_next').click(function(){
		
					window.location.replace("../repayment_details/还款明细.html");
					
		 			localStorage.setItem("monthly_principal_hpf", monthly_principal_hpf);   //每月应还本金-公积金
		 			localStorage.setItem("monthly_principal_commercial", monthly_principal_commercial); //每月应还本金-商业贷
		 			localStorage.setItem("year2", year2);  //期限
		 			localStorage.setItem("pric2", pric2);  //贷款总额
		 			localStorage.setItem("price_hpf",price_hpf);//公积金贷款总额
					localStorage.setItem("lending_rate_hpf", lending_rate_hpf);//公积金贷款利率
					localStorage.setItem("price_commercial",price_commercial);//商业贷款总额
					localStorage.setItem("lending_rate_commercial", lending_rate_commercial);//商业贷款利率
					localStorage.setItem("mortgage_Calculator", 3);  
		
				});
				
				
			var myChart_one = echarts.init(document.getElementById('echart_box_one'));
			var option_one = {
			    toolbox: {
			        show : false,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'center',
			                        max: 1548
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : false,
			    series : [
			        {
			        
			            type:'pie',
			             radius : ['30%','50%' ],
			              center : ['50%', '65%'],
			            itemStyle : {
			                normal : {
			                    label : {
			                        show : true,
			                        formatter:"{b}\n{c}",
			                        textStyle:{
			                        	fontSize:12
			                        }
			                    },
			                    labelLine : {
			                        show : true,
			                        length:20,
			                    }
			                },
			                emphasis : {
			                    label : {
			                        show : true,
			                        position : 'center',
			                        textStyle : {
			                            fontSize : '14',
			                            fontWeight : 'bold'
			                        }
			                    }
			                }
			            },
			            data:[
			                {value:pric2, name:'贷款总额'},
			                {value:interest_bx, name:'支付利息'}
			            ]
			        }
			    ]
		};
      // 为echarts对象加载数据 
        myChart_one.setOption(option_one);              
		
			var myChart_two = echarts.init(document.getElementById('echart_box_two'));
			var option_two = {
			    toolbox: {
			        show : false,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'center',
			                        max: 1548
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : false,
			    series : [
			        {
			       
			            type:'pie',
			             radius : ['30%','50%' ],
			              center : ['50%', '65%'],
			            itemStyle : {
			                normal : {
			                    label : {
			                        show : true,
			                        formatter:"{b}\n{c}",
			                        textStyle:{
			                        	fontSize:12
			                        }
			                    },
			                    labelLine : {
			                        show : true,
			                        length:20,
			                    }
			                },
			                emphasis : {
			                    label : {
			                        show : true,
			                        position : 'center',
			                        textStyle : {
			                            fontSize : '14',
			                            fontWeight : 'bold'
			                        }
			                    }
			                }
			            },
			            data:[
			                {value:pric2, name:'贷款总额'},
			                {value:interest2_bj, name:'支付利息'}
			            ]
			        }
			    ]
		};
      // 为echarts对象加载数据 
        myChart_two.setOption(option_two);	
				
				
	}
	

})